<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>zxxhouse: src/com/zxx/PullRefresh/PullToRefreshLayout.java源文件</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">zxxhouse
   &#160;<span id="projectnumber">1.0</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- 制作者 Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="annotated.html"><span>类</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>文件列表</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">src/com/zxx/PullRefresh/PullToRefreshLayout.java</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>com.zxx.PullRefresh;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> java.util.Timer;
<a name="l00004"></a>00004 <span class="keyword">import</span> java.util.TimerTask;
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="keyword">import</span> android.content.Context;
<a name="l00007"></a>00007 <span class="keyword">import</span> android.content.res.Resources;
<a name="l00008"></a>00008 <span class="keyword">import</span> android.graphics.Canvas;
<a name="l00009"></a>00009 <span class="keyword">import</span> android.graphics.LinearGradient;
<a name="l00010"></a>00010 <span class="keyword">import</span> android.graphics.Paint;
<a name="l00011"></a>00011 <span class="keyword">import</span> android.graphics.Paint.Style;
<a name="l00012"></a>00012 <span class="keyword">import</span> android.graphics.RectF;
<a name="l00013"></a>00013 <span class="keyword">import</span> android.graphics.Shader.TileMode;
<a name="l00014"></a>00014 <span class="keyword">import</span> android.os.Handler;
<a name="l00015"></a>00015 <span class="keyword">import</span> android.os.Message;
<a name="l00016"></a>00016 <span class="keyword">import</span> android.util.AttributeSet;
<a name="l00017"></a>00017 <span class="keyword">import</span> android.util.Log;
<a name="l00018"></a>00018 <span class="keyword">import</span> android.view.MotionEvent;
<a name="l00019"></a>00019 <span class="keyword">import</span> android.view.View;
<a name="l00020"></a>00020 <span class="keyword">import</span> android.view.ViewGroup;
<a name="l00021"></a>00021 <span class="keyword">import</span> android.view.animation.AnimationUtils;
<a name="l00022"></a>00022 <span class="keyword">import</span> android.view.animation.LinearInterpolator;
<a name="l00023"></a>00023 <span class="keyword">import</span> android.view.animation.RotateAnimation;
<a name="l00024"></a>00024 <span class="keyword">import</span> android.widget.RelativeLayout;
<a name="l00025"></a>00025 <span class="keyword">import</span> android.widget.TextView;
<a name="l00026"></a>00026 <span class="keyword">import</span> com.zxx.PullRefresh.Pullable;
<a name="l00027"></a>00027 <span class="keyword">import</span> com.soufang.ui.*;
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 
<a name="l00038"></a><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html">00038</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html" title="自定义的布局，用来管理三个子控件，其中一个是下拉头，一个是包含内容的pullableView（可以是实现Pullable接口的的任何View）， 还有一个上拉头，更多详解见博客http://blog.csdn.net/zhongkejingwang/article/details/38868463">PullToRefreshLayout</a> <span class="keyword">extends</span> RelativeLayout
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String TAG = <span class="stringliteral">&quot;PullToRefreshLayout&quot;</span>;
<a name="l00041"></a>00041         <span class="comment">// 初始状态</span>
<a name="l00042"></a>00042         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> INIT = 0;
<a name="l00043"></a>00043         <span class="comment">// 释放刷新</span>
<a name="l00044"></a>00044         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> RELEASE_TO_REFRESH = 1;
<a name="l00045"></a>00045         <span class="comment">// 正在刷新</span>
<a name="l00046"></a>00046         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> REFRESHING = 2;
<a name="l00047"></a>00047         <span class="comment">// 释放加载</span>
<a name="l00048"></a>00048         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> RELEASE_TO_LOAD = 3;
<a name="l00049"></a>00049         <span class="comment">// 正在加载</span>
<a name="l00050"></a>00050         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> LOADING = 4;
<a name="l00051"></a>00051         <span class="comment">// 操作完毕</span>
<a name="l00052"></a>00052         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> DONE = 5;
<a name="l00053"></a>00053         <span class="comment">// 当前状态</span>
<a name="l00054"></a>00054         <span class="keyword">private</span> <span class="keywordtype">int</span> state = INIT;
<a name="l00055"></a>00055         <span class="comment">// 刷新回调接口</span>
<a name="l00056"></a>00056         <span class="keyword">private</span> <a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html" title="刷新加载回调接口">OnRefreshListener</a> mListener;
<a name="l00057"></a>00057         <span class="comment">// 刷新成功</span>
<a name="l00058"></a>00058         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> SUCCEED = 0;
<a name="l00059"></a>00059         <span class="comment">// 刷新失败</span>
<a name="l00060"></a>00060         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keywordtype">int</span> FAIL = 1;
<a name="l00061"></a>00061         <span class="comment">// 按下Y坐标，上一个事件点Y坐标</span>
<a name="l00062"></a>00062         <span class="keyword">private</span> <span class="keywordtype">float</span> downY, lastY;
<a name="l00063"></a>00063 
<a name="l00064"></a>00064         <span class="comment">// 下拉的距离。注意：pullDownY和pullUpY不可能同时不为0</span>
<a name="l00065"></a>00065         <span class="keyword">public</span> <span class="keywordtype">float</span> pullDownY = 0;
<a name="l00066"></a>00066         <span class="comment">// 上拉的距离</span>
<a name="l00067"></a>00067         <span class="keyword">private</span> <span class="keywordtype">float</span> pullUpY = 0;
<a name="l00068"></a>00068 
<a name="l00069"></a>00069         <span class="comment">// 释放刷新的距离</span>
<a name="l00070"></a>00070         <span class="keyword">private</span> <span class="keywordtype">float</span> refreshDist = 200;
<a name="l00071"></a>00071         <span class="comment">// 释放加载的距离</span>
<a name="l00072"></a>00072         <span class="keyword">private</span> <span class="keywordtype">float</span> loadmoreDist = 200;
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         <span class="keyword">private</span> MyTimer timer;
<a name="l00075"></a>00075         <span class="comment">// 回滚速度</span>
<a name="l00076"></a>00076         <span class="keyword">public</span> <span class="keywordtype">float</span> MOVE_SPEED = 8;
<a name="l00077"></a>00077         <span class="comment">// 第一次执行布局</span>
<a name="l00078"></a>00078         <span class="keyword">private</span> <span class="keywordtype">boolean</span> isLayout = <span class="keyword">false</span>;
<a name="l00079"></a>00079         <span class="comment">// 在刷新过程中滑动操作</span>
<a name="l00080"></a>00080         <span class="keyword">private</span> <span class="keywordtype">boolean</span> isTouch = <span class="keyword">false</span>;
<a name="l00081"></a>00081         <span class="comment">// 手指滑动距离与下拉头的滑动距离比，中间会随正切函数变化</span>
<a name="l00082"></a>00082         <span class="keyword">private</span> <span class="keywordtype">float</span> radio = 2;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084         <span class="comment">// 下拉箭头的转180°动画</span>
<a name="l00085"></a>00085         <span class="keyword">private</span> RotateAnimation rotateAnimation;
<a name="l00086"></a>00086         <span class="comment">// 均匀旋转动画</span>
<a name="l00087"></a>00087         <span class="keyword">private</span> RotateAnimation refreshingAnimation;
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         <span class="comment">// 下拉头</span>
<a name="l00090"></a>00090         <span class="keyword">private</span> View refreshView;
<a name="l00091"></a>00091         <span class="comment">// 下拉的箭头</span>
<a name="l00092"></a>00092         <span class="keyword">private</span> View pullView;
<a name="l00093"></a>00093         <span class="comment">// 正在刷新的图标</span>
<a name="l00094"></a>00094         <span class="keyword">private</span> View refreshingView;
<a name="l00095"></a>00095         <span class="comment">// 刷新结果图标</span>
<a name="l00096"></a>00096         <span class="keyword">private</span> View refreshStateImageView;
<a name="l00097"></a>00097         <span class="comment">// 刷新结果：成功或失败</span>
<a name="l00098"></a>00098         <span class="keyword">private</span> TextView refreshStateTextView;
<a name="l00099"></a>00099 
<a name="l00100"></a>00100         <span class="comment">// 上拉头</span>
<a name="l00101"></a>00101         <span class="keyword">private</span> View loadmoreView;
<a name="l00102"></a>00102         <span class="comment">// 上拉的箭头</span>
<a name="l00103"></a>00103         <span class="keyword">private</span> View pullUpView;
<a name="l00104"></a>00104         <span class="comment">// 正在加载的图标</span>
<a name="l00105"></a>00105         <span class="keyword">private</span> View loadingView;
<a name="l00106"></a>00106         <span class="comment">// 加载结果图标</span>
<a name="l00107"></a>00107         <span class="keyword">private</span> View loadStateImageView;
<a name="l00108"></a>00108         <span class="comment">// 加载结果：成功或失败</span>
<a name="l00109"></a>00109         <span class="keyword">private</span> TextView loadStateTextView;
<a name="l00110"></a>00110 
<a name="l00111"></a>00111         <span class="comment">// 实现了Pullable接口的View</span>
<a name="l00112"></a>00112         <span class="keyword">private</span> View pullableView;
<a name="l00113"></a>00113         <span class="comment">// 过滤多点触碰</span>
<a name="l00114"></a>00114         <span class="keyword">private</span> <span class="keywordtype">int</span> mEvents;
<a name="l00115"></a>00115         <span class="comment">// 这两个变量用来控制pull的方向，如果不加控制，当情况满足可上拉又可下拉时没法下拉</span>
<a name="l00116"></a>00116         <span class="keyword">private</span> <span class="keywordtype">boolean</span> canPullDown = <span class="keyword">true</span>;
<a name="l00117"></a>00117         <span class="keyword">private</span> <span class="keywordtype">boolean</span> canPullUp = <span class="keyword">true</span>;
<a name="l00118"></a>00118 
<a name="l00122"></a><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ab4df3a5e9f047c654c30fbb6fcc3d8f8">00122</a>         Handler <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ab4df3a5e9f047c654c30fbb6fcc3d8f8" title="执行自动回滚的handler">updateHandler</a> = <span class="keyword">new</span> Handler()
<a name="l00123"></a>00123         {
<a name="l00124"></a>00124 
<a name="l00125"></a>00125                 @Override
<a name="l00126"></a>00126                 <span class="keyword">public</span> <span class="keywordtype">void</span> handleMessage(Message msg)
<a name="l00127"></a>00127                 {
<a name="l00128"></a>00128                         <span class="comment">// 回弹速度随下拉距离moveDeltaY增大而增大</span>
<a name="l00129"></a>00129                         MOVE_SPEED = (float) (8 + 5 * Math.tan(Math.PI / 2
<a name="l00130"></a>00130                                         / getMeasuredHeight() * (pullDownY + Math.abs(pullUpY))));
<a name="l00131"></a>00131                         <span class="keywordflow">if</span> (!isTouch)
<a name="l00132"></a>00132                         {
<a name="l00133"></a>00133                                 <span class="comment">// 正在刷新，且没有往上推的话则悬停，显示&quot;正在刷新...&quot;</span>
<a name="l00134"></a>00134                                 <span class="keywordflow">if</span> (state == REFRESHING &amp;&amp; pullDownY &lt;= refreshDist)
<a name="l00135"></a>00135                                 {
<a name="l00136"></a>00136                                         pullDownY = refreshDist;
<a name="l00137"></a>00137                                         timer.cancel();
<a name="l00138"></a>00138                                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (state == LOADING &amp;&amp; -pullUpY &lt;= loadmoreDist)
<a name="l00139"></a>00139                                 {
<a name="l00140"></a>00140                                         pullUpY = -loadmoreDist;
<a name="l00141"></a>00141                                         timer.cancel();
<a name="l00142"></a>00142                                 }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144                         }
<a name="l00145"></a>00145                         <span class="keywordflow">if</span> (pullDownY &gt; 0)
<a name="l00146"></a>00146                                 pullDownY -= MOVE_SPEED;
<a name="l00147"></a>00147                         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pullUpY &lt; 0)
<a name="l00148"></a>00148                                 pullUpY += MOVE_SPEED;
<a name="l00149"></a>00149                         <span class="keywordflow">if</span> (pullDownY &lt; 0)
<a name="l00150"></a>00150                         {
<a name="l00151"></a>00151                                 <span class="comment">// 已完成回弹</span>
<a name="l00152"></a>00152                                 pullDownY = 0;
<a name="l00153"></a>00153                                 pullView.clearAnimation();
<a name="l00154"></a>00154                                 <span class="comment">// 隐藏下拉头时有可能还在刷新，只有当前状态不是正在刷新时才改变状态</span>
<a name="l00155"></a>00155                                 <span class="keywordflow">if</span> (state != REFRESHING &amp;&amp; state != LOADING)
<a name="l00156"></a>00156                                         changeState(INIT);
<a name="l00157"></a>00157                                 timer.cancel();
<a name="l00158"></a>00158                         }
<a name="l00159"></a>00159                         <span class="keywordflow">if</span> (pullUpY &gt; 0)
<a name="l00160"></a>00160                         {
<a name="l00161"></a>00161                                 <span class="comment">// 已完成回弹</span>
<a name="l00162"></a>00162                                 pullUpY = 0;
<a name="l00163"></a>00163                                 pullUpView.clearAnimation();
<a name="l00164"></a>00164                                 <span class="comment">// 隐藏下拉头时有可能还在刷新，只有当前状态不是正在刷新时才改变状态</span>
<a name="l00165"></a>00165                                 <span class="keywordflow">if</span> (state != REFRESHING &amp;&amp; state != LOADING)
<a name="l00166"></a>00166                                         changeState(INIT);
<a name="l00167"></a>00167                                 timer.cancel();
<a name="l00168"></a>00168                         }
<a name="l00169"></a>00169                         <span class="comment">// 刷新布局,会自动调用onLayout</span>
<a name="l00170"></a>00170                         requestLayout();
<a name="l00171"></a>00171                 }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173         };
<a name="l00174"></a>00174 
<a name="l00175"></a>00175         <span class="keyword">public</span> <span class="keywordtype">void</span> setOnRefreshListener(<a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html" title="刷新加载回调接口">OnRefreshListener</a> listener)
<a name="l00176"></a>00176         {
<a name="l00177"></a>00177                 mListener = listener;
<a name="l00178"></a>00178         }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180         <span class="keyword">public</span> PullToRefreshLayout(Context context)
<a name="l00181"></a>00181         {
<a name="l00182"></a>00182                 super(context);
<a name="l00183"></a>00183                 initView(context);
<a name="l00184"></a>00184         }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186         <span class="keyword">public</span> PullToRefreshLayout(Context context, AttributeSet attrs)
<a name="l00187"></a>00187         {
<a name="l00188"></a>00188                 super(context, attrs);
<a name="l00189"></a>00189                 initView(context);
<a name="l00190"></a>00190         }
<a name="l00191"></a>00191 
<a name="l00192"></a>00192         <span class="keyword">public</span> PullToRefreshLayout(Context context, AttributeSet attrs, <span class="keywordtype">int</span> defStyle)
<a name="l00193"></a>00193         {
<a name="l00194"></a>00194                 super(context, attrs, defStyle);
<a name="l00195"></a>00195                 initView(context);
<a name="l00196"></a>00196         }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <span class="keyword">private</span> <span class="keywordtype">void</span> initView(Context context)
<a name="l00199"></a>00199         {
<a name="l00200"></a>00200                 timer = <span class="keyword">new</span> MyTimer(<a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ab4df3a5e9f047c654c30fbb6fcc3d8f8" title="执行自动回滚的handler">updateHandler</a>);
<a name="l00201"></a>00201                 rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(
<a name="l00202"></a>00202                                 context, R.anim.reverse_anim);
<a name="l00203"></a>00203                 refreshingAnimation = (RotateAnimation) AnimationUtils.loadAnimation(
<a name="l00204"></a>00204                                 context, R.anim.rotating);
<a name="l00205"></a>00205                 <span class="comment">// 添加匀速转动动画</span>
<a name="l00206"></a>00206                 LinearInterpolator lir = <span class="keyword">new</span> LinearInterpolator();
<a name="l00207"></a>00207                 rotateAnimation.setInterpolator(lir);
<a name="l00208"></a>00208                 refreshingAnimation.setInterpolator(lir);
<a name="l00209"></a>00209         }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211         <span class="keyword">private</span> <span class="keywordtype">void</span> hide()
<a name="l00212"></a>00212         {
<a name="l00213"></a>00213                 timer.schedule(5);
<a name="l00214"></a>00214         }
<a name="l00215"></a>00215 
<a name="l00223"></a><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#a2237f88388138031e14df06d258db3ef">00223</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#a2237f88388138031e14df06d258db3ef" title="完成刷新操作，显示刷新结果。注意：刷新完成后一定要调用这个方法">refreshFinish</a>(<span class="keywordtype">int</span> refreshResult)
<a name="l00224"></a>00224         {
<a name="l00225"></a>00225                 refreshingView.clearAnimation();
<a name="l00226"></a>00226                 refreshingView.setVisibility(View.GONE);
<a name="l00227"></a>00227                 <span class="keywordflow">switch</span> (refreshResult)
<a name="l00228"></a>00228                 {
<a name="l00229"></a>00229                 <span class="keywordflow">case</span> SUCCEED:
<a name="l00230"></a>00230                         <span class="comment">// 刷新成功</span>
<a name="l00231"></a>00231                         refreshStateImageView.setVisibility(View.VISIBLE);
<a name="l00232"></a>00232                         refreshStateTextView.setText(R.string.refresh_succeed);
<a name="l00233"></a>00233                         refreshStateImageView
<a name="l00234"></a>00234                                         .setBackgroundResource(R.drawable.refresh_succeed);
<a name="l00235"></a>00235                         <span class="keywordflow">break</span>;
<a name="l00236"></a>00236                 <span class="keywordflow">case</span> FAIL:
<a name="l00237"></a>00237                 <span class="keywordflow">default</span>:
<a name="l00238"></a>00238                         <span class="comment">// 刷新失败</span>
<a name="l00239"></a>00239                         refreshStateImageView.setVisibility(View.VISIBLE);
<a name="l00240"></a>00240                         refreshStateTextView.setText(R.string.refresh_fail);
<a name="l00241"></a>00241                         refreshStateImageView
<a name="l00242"></a>00242                                         .setBackgroundResource(R.drawable.refresh_failed);
<a name="l00243"></a>00243                         <span class="keywordflow">break</span>;
<a name="l00244"></a>00244                 }
<a name="l00245"></a>00245                 <span class="comment">// 刷新结果停留1秒</span>
<a name="l00246"></a>00246                 <span class="keyword">new</span> Handler()
<a name="l00247"></a>00247                 {
<a name="l00248"></a>00248                         @Override
<a name="l00249"></a>00249                         <span class="keyword">public</span> <span class="keywordtype">void</span> handleMessage(Message msg)
<a name="l00250"></a>00250                         {
<a name="l00251"></a>00251                                 changeState(DONE);
<a name="l00252"></a>00252                                 hide();
<a name="l00253"></a>00253                         }
<a name="l00254"></a>00254                 }.sendEmptyMessageDelayed(0, 1000);
<a name="l00255"></a>00255         }
<a name="l00256"></a>00256 
<a name="l00263"></a><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#a33f0f53e48b89416f901283fcb2ba1be">00263</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#a33f0f53e48b89416f901283fcb2ba1be" title="加载完毕，显示加载结果。注意：加载完成后一定要调用这个方法">loadmoreFinish</a>(<span class="keywordtype">int</span> refreshResult)
<a name="l00264"></a>00264         {
<a name="l00265"></a>00265                 loadingView.clearAnimation();
<a name="l00266"></a>00266                 loadingView.setVisibility(View.GONE);
<a name="l00267"></a>00267                 <span class="keywordflow">switch</span> (refreshResult)
<a name="l00268"></a>00268                 {
<a name="l00269"></a>00269                 <span class="keywordflow">case</span> SUCCEED:
<a name="l00270"></a>00270                         <span class="comment">// 加载成功</span>
<a name="l00271"></a>00271                         loadStateImageView.setVisibility(View.VISIBLE);
<a name="l00272"></a>00272                         loadStateTextView.setText(R.string.load_succeed);
<a name="l00273"></a>00273                         loadStateImageView.setBackgroundResource(R.drawable.load_succeed);
<a name="l00274"></a>00274                         <span class="keywordflow">break</span>;
<a name="l00275"></a>00275                 <span class="keywordflow">case</span> FAIL:
<a name="l00276"></a>00276                 <span class="keywordflow">default</span>:
<a name="l00277"></a>00277                         <span class="comment">// 加载失败</span>
<a name="l00278"></a>00278                         loadStateImageView.setVisibility(View.VISIBLE);
<a name="l00279"></a>00279                         loadStateTextView.setText(R.string.load_fail);
<a name="l00280"></a>00280                         loadStateImageView.setBackgroundResource(R.drawable.load_failed);
<a name="l00281"></a>00281                         <span class="keywordflow">break</span>;
<a name="l00282"></a>00282                 }
<a name="l00283"></a>00283                 <span class="comment">// 刷新结果停留1秒</span>
<a name="l00284"></a>00284                 <span class="keyword">new</span> Handler()
<a name="l00285"></a>00285                 {
<a name="l00286"></a>00286                         @Override
<a name="l00287"></a>00287                         <span class="keyword">public</span> <span class="keywordtype">void</span> handleMessage(Message msg)
<a name="l00288"></a>00288                         {
<a name="l00289"></a>00289                                 changeState(DONE);
<a name="l00290"></a>00290                                 hide();
<a name="l00291"></a>00291                         }
<a name="l00292"></a>00292                 }.sendEmptyMessageDelayed(0, 1000);
<a name="l00293"></a>00293         }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295         <span class="keyword">private</span> <span class="keywordtype">void</span> changeState(<span class="keywordtype">int</span> to)
<a name="l00296"></a>00296         {
<a name="l00297"></a>00297                 state = to;
<a name="l00298"></a>00298                 <span class="keywordflow">switch</span> (state)
<a name="l00299"></a>00299                 {
<a name="l00300"></a>00300                 <span class="keywordflow">case</span> INIT:
<a name="l00301"></a>00301                         <span class="comment">// 下拉布局初始状态</span>
<a name="l00302"></a>00302                         refreshStateImageView.setVisibility(View.GONE);
<a name="l00303"></a>00303                         refreshStateTextView.setText(R.string.pull_to_refresh);
<a name="l00304"></a>00304                         pullView.clearAnimation();
<a name="l00305"></a>00305                         pullView.setVisibility(View.VISIBLE);
<a name="l00306"></a>00306                         <span class="comment">// 上拉布局初始状态</span>
<a name="l00307"></a>00307                         loadStateImageView.setVisibility(View.GONE);
<a name="l00308"></a>00308                         loadStateTextView.setText(R.string.pullup_to_load);
<a name="l00309"></a>00309                         pullUpView.clearAnimation();
<a name="l00310"></a>00310                         pullUpView.setVisibility(View.VISIBLE);
<a name="l00311"></a>00311                         <span class="keywordflow">break</span>;
<a name="l00312"></a>00312                 <span class="keywordflow">case</span> RELEASE_TO_REFRESH:
<a name="l00313"></a>00313                         <span class="comment">// 释放刷新状态</span>
<a name="l00314"></a>00314                         refreshStateTextView.setText(R.string.release_to_refresh);
<a name="l00315"></a>00315                         pullView.startAnimation(rotateAnimation);
<a name="l00316"></a>00316                         <span class="keywordflow">break</span>;
<a name="l00317"></a>00317                 <span class="keywordflow">case</span> REFRESHING:
<a name="l00318"></a>00318                         <span class="comment">// 正在刷新状态</span>
<a name="l00319"></a>00319                         pullView.clearAnimation();
<a name="l00320"></a>00320                         refreshingView.setVisibility(View.VISIBLE);
<a name="l00321"></a>00321                         pullView.setVisibility(View.INVISIBLE);
<a name="l00322"></a>00322                         refreshingView.startAnimation(refreshingAnimation);
<a name="l00323"></a>00323                         refreshStateTextView.setText(R.string.refreshing);
<a name="l00324"></a>00324                         <span class="keywordflow">break</span>;
<a name="l00325"></a>00325                 <span class="keywordflow">case</span> RELEASE_TO_LOAD:
<a name="l00326"></a>00326                         <span class="comment">// 释放加载状态</span>
<a name="l00327"></a>00327                         loadStateTextView.setText(R.string.release_to_load);
<a name="l00328"></a>00328                         pullUpView.startAnimation(rotateAnimation);
<a name="l00329"></a>00329                         <span class="keywordflow">break</span>;
<a name="l00330"></a>00330                 <span class="keywordflow">case</span> LOADING:
<a name="l00331"></a>00331                         <span class="comment">// 正在加载状态</span>
<a name="l00332"></a>00332                         pullUpView.clearAnimation();
<a name="l00333"></a>00333                         loadingView.setVisibility(View.VISIBLE);
<a name="l00334"></a>00334                         pullUpView.setVisibility(View.INVISIBLE);
<a name="l00335"></a>00335                         loadingView.startAnimation(refreshingAnimation);
<a name="l00336"></a>00336                         loadStateTextView.setText(R.string.loading);
<a name="l00337"></a>00337                         <span class="keywordflow">break</span>;
<a name="l00338"></a>00338                 <span class="keywordflow">case</span> DONE:
<a name="l00339"></a>00339                         <span class="comment">// 刷新或加载完毕，啥都不做</span>
<a name="l00340"></a>00340                         <span class="keywordflow">break</span>;
<a name="l00341"></a>00341                 }
<a name="l00342"></a>00342         }
<a name="l00343"></a>00343 
<a name="l00347"></a><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ac4068626101cb1f37d14e81e645bd468">00347</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ac4068626101cb1f37d14e81e645bd468" title="不限制上拉或下拉">releasePull</a>()
<a name="l00348"></a>00348         {
<a name="l00349"></a>00349                 canPullDown = <span class="keyword">true</span>;
<a name="l00350"></a>00350                 canPullUp = <span class="keyword">true</span>;
<a name="l00351"></a>00351         }
<a name="l00352"></a>00352 
<a name="l00358"></a>00358         @Override
<a name="l00359"></a><a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#af69e026bc4f7ce8e4ed50bee5eed24fa">00359</a>         <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#af69e026bc4f7ce8e4ed50bee5eed24fa" title="（非 Javadoc）由父控件决定是否分发事件，防止事件冲突">dispatchTouchEvent</a>(MotionEvent ev)
<a name="l00360"></a>00360         {
<a name="l00361"></a>00361                 <span class="keywordflow">switch</span> (ev.getActionMasked())
<a name="l00362"></a>00362                 {
<a name="l00363"></a>00363                 <span class="keywordflow">case</span> MotionEvent.ACTION_DOWN:
<a name="l00364"></a>00364                         downY = ev.getY();
<a name="l00365"></a>00365                         lastY = downY;
<a name="l00366"></a>00366                         timer.cancel();
<a name="l00367"></a>00367                         mEvents = 0;
<a name="l00368"></a>00368                         <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ac4068626101cb1f37d14e81e645bd468" title="不限制上拉或下拉">releasePull</a>();
<a name="l00369"></a>00369                         <span class="keywordflow">break</span>;
<a name="l00370"></a>00370                 <span class="keywordflow">case</span> MotionEvent.ACTION_POINTER_DOWN:
<a name="l00371"></a>00371                 <span class="keywordflow">case</span> MotionEvent.ACTION_POINTER_UP:
<a name="l00372"></a>00372                         <span class="comment">// 过滤多点触碰</span>
<a name="l00373"></a>00373                         mEvents = -1;
<a name="l00374"></a>00374                         <span class="keywordflow">break</span>;
<a name="l00375"></a>00375                 <span class="keywordflow">case</span> MotionEvent.ACTION_MOVE:
<a name="l00376"></a>00376                         <span class="keywordflow">if</span> (mEvents == 0)
<a name="l00377"></a>00377                         {
<a name="l00378"></a>00378                                 <span class="keywordflow">if</span> (((Pullable) pullableView).canPullDown() &amp;&amp; canPullDown
<a name="l00379"></a>00379                                                 &amp;&amp; state != LOADING)
<a name="l00380"></a>00380                                 {
<a name="l00381"></a>00381                                         <span class="comment">// 可以下拉，正在加载时不能下拉</span>
<a name="l00382"></a>00382                                         <span class="comment">// 对实际滑动距离做缩小，造成用力拉的感觉</span>
<a name="l00383"></a>00383                                         pullDownY = pullDownY + (ev.getY() - lastY) / radio;
<a name="l00384"></a>00384                                         <span class="keywordflow">if</span> (pullDownY &lt; 0)
<a name="l00385"></a>00385                                         {
<a name="l00386"></a>00386                                                 pullDownY = 0;
<a name="l00387"></a>00387                                                 canPullDown = <span class="keyword">false</span>;
<a name="l00388"></a>00388                                                 canPullUp = <span class="keyword">true</span>;
<a name="l00389"></a>00389                                         }
<a name="l00390"></a>00390                                         <span class="keywordflow">if</span> (pullDownY &gt; getMeasuredHeight())
<a name="l00391"></a>00391                                                 pullDownY = getMeasuredHeight();
<a name="l00392"></a>00392                                         <span class="keywordflow">if</span> (state == REFRESHING)
<a name="l00393"></a>00393                                         {
<a name="l00394"></a>00394                                                 <span class="comment">// 正在刷新的时候触摸移动</span>
<a name="l00395"></a>00395                                                 isTouch = <span class="keyword">true</span>;
<a name="l00396"></a>00396                                         }
<a name="l00397"></a>00397                                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (((Pullable) pullableView).canPullUp() &amp;&amp; canPullUp
<a name="l00398"></a>00398                                                 &amp;&amp; state != REFRESHING)
<a name="l00399"></a>00399                                 {
<a name="l00400"></a>00400                                         <span class="comment">// 可以上拉，正在刷新时不能上拉</span>
<a name="l00401"></a>00401                                         pullUpY = pullUpY + (ev.getY() - lastY) / radio;
<a name="l00402"></a>00402                                         <span class="keywordflow">if</span> (pullUpY &gt; 0)
<a name="l00403"></a>00403                                         {
<a name="l00404"></a>00404                                                 pullUpY = 0;
<a name="l00405"></a>00405                                                 canPullDown = <span class="keyword">true</span>;
<a name="l00406"></a>00406                                                 canPullUp = <span class="keyword">false</span>;
<a name="l00407"></a>00407                                         }
<a name="l00408"></a>00408                                         <span class="keywordflow">if</span> (pullUpY &lt; -getMeasuredHeight())
<a name="l00409"></a>00409                                                 pullUpY = -getMeasuredHeight();
<a name="l00410"></a>00410                                         <span class="keywordflow">if</span> (state == LOADING)
<a name="l00411"></a>00411                                         {
<a name="l00412"></a>00412                                                 <span class="comment">// 正在加载的时候触摸移动</span>
<a name="l00413"></a>00413                                                 isTouch = <span class="keyword">true</span>;
<a name="l00414"></a>00414                                         }
<a name="l00415"></a>00415                                 } <span class="keywordflow">else</span>
<a name="l00416"></a>00416                                         <a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html#ac4068626101cb1f37d14e81e645bd468" title="不限制上拉或下拉">releasePull</a>();
<a name="l00417"></a>00417                         } <span class="keywordflow">else</span>
<a name="l00418"></a>00418                                 mEvents = 0;
<a name="l00419"></a>00419                         lastY = ev.getY();
<a name="l00420"></a>00420                         <span class="comment">// 根据下拉距离改变比例</span>
<a name="l00421"></a>00421                         radio = (float) (2 + 2 * Math.tan(Math.PI / 2 / getMeasuredHeight()
<a name="l00422"></a>00422                                         * (pullDownY + Math.abs(pullUpY))));
<a name="l00423"></a>00423                         requestLayout();
<a name="l00424"></a>00424                         <span class="keywordflow">if</span> (pullDownY &lt;= refreshDist &amp;&amp; state == RELEASE_TO_REFRESH)
<a name="l00425"></a>00425                         {
<a name="l00426"></a>00426                                 <span class="comment">// 如果下拉距离没达到刷新的距离且当前状态是释放刷新，改变状态为下拉刷新</span>
<a name="l00427"></a>00427                                 changeState(INIT);
<a name="l00428"></a>00428                         }
<a name="l00429"></a>00429                         <span class="keywordflow">if</span> (pullDownY &gt;= refreshDist &amp;&amp; state == INIT)
<a name="l00430"></a>00430                         {
<a name="l00431"></a>00431                                 <span class="comment">// 如果下拉距离达到刷新的距离且当前状态是初始状态刷新，改变状态为释放刷新</span>
<a name="l00432"></a>00432                                 changeState(RELEASE_TO_REFRESH);
<a name="l00433"></a>00433                         }
<a name="l00434"></a>00434                         <span class="comment">// 下面是判断上拉加载的，同上，注意pullUpY是负值</span>
<a name="l00435"></a>00435                         <span class="keywordflow">if</span> (-pullUpY &lt;= loadmoreDist &amp;&amp; state == RELEASE_TO_LOAD)
<a name="l00436"></a>00436                         {
<a name="l00437"></a>00437                                 changeState(INIT);
<a name="l00438"></a>00438                         }
<a name="l00439"></a>00439                         <span class="keywordflow">if</span> (-pullUpY &gt;= loadmoreDist &amp;&amp; state == INIT)
<a name="l00440"></a>00440                         {
<a name="l00441"></a>00441                                 changeState(RELEASE_TO_LOAD);
<a name="l00442"></a>00442                         }
<a name="l00443"></a>00443                         <span class="comment">// 因为刷新和加载操作不能同时进行，所以pullDownY和pullUpY不会同时不为0，因此这里用(pullDownY +</span>
<a name="l00444"></a>00444                         <span class="comment">// Math.abs(pullUpY))就可以不对当前状态作区分了</span>
<a name="l00445"></a>00445                         <span class="keywordflow">if</span> ((pullDownY + Math.abs(pullUpY)) &gt; 8)
<a name="l00446"></a>00446                         {
<a name="l00447"></a>00447                                 <span class="comment">// 防止下拉过程中误触发长按事件和点击事件</span>
<a name="l00448"></a>00448                                 ev.setAction(MotionEvent.ACTION_CANCEL);
<a name="l00449"></a>00449                         }
<a name="l00450"></a>00450                         <span class="keywordflow">break</span>;
<a name="l00451"></a>00451                 <span class="keywordflow">case</span> MotionEvent.ACTION_UP:
<a name="l00452"></a>00452                         <span class="keywordflow">if</span> (pullDownY &gt; refreshDist || -pullUpY &gt; loadmoreDist)
<a name="l00453"></a>00453                                 <span class="comment">// 正在刷新时往下拉（正在加载时往上拉），释放后下拉头（上拉头）不隐藏</span>
<a name="l00454"></a>00454                                 isTouch = <span class="keyword">false</span>;
<a name="l00455"></a>00455                         <span class="keywordflow">if</span> (state == RELEASE_TO_REFRESH)
<a name="l00456"></a>00456                         {
<a name="l00457"></a>00457                                 changeState(REFRESHING);
<a name="l00458"></a>00458                                 <span class="comment">// 刷新操作</span>
<a name="l00459"></a>00459                                 <span class="keywordflow">if</span> (mListener != null)
<a name="l00460"></a>00460                                         mListener.<a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html#a54dbbaff3fae4c145e5a3efb3bc0b173" title="刷新操作">onRefresh</a>(<span class="keyword">this</span>);
<a name="l00461"></a>00461                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (state == RELEASE_TO_LOAD)
<a name="l00462"></a>00462                         {
<a name="l00463"></a>00463                                 changeState(LOADING);
<a name="l00464"></a>00464                                 <span class="comment">// 加载操作</span>
<a name="l00465"></a>00465                                 <span class="keywordflow">if</span> (mListener != null)
<a name="l00466"></a>00466                                         mListener.<a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html#aec3a5a5dc7b68d7838a447199534ebf2" title="加载操作">onLoadMore</a>(<span class="keyword">this</span>);
<a name="l00467"></a>00467                         }
<a name="l00468"></a>00468                         hide();
<a name="l00469"></a>00469                 <span class="keywordflow">default</span>:
<a name="l00470"></a>00470                         <span class="keywordflow">break</span>;
<a name="l00471"></a>00471                 }
<a name="l00472"></a>00472                 <span class="comment">// 事件分发交给父类</span>
<a name="l00473"></a>00473                 super.dispatchTouchEvent(ev);
<a name="l00474"></a>00474                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00475"></a>00475         }
<a name="l00476"></a>00476 
<a name="l00477"></a>00477         <span class="keyword">private</span> <span class="keywordtype">void</span> initView()
<a name="l00478"></a>00478         {
<a name="l00479"></a>00479                 <span class="comment">// 初始化下拉布局</span>
<a name="l00480"></a>00480                 pullView = refreshView.findViewById(R.id.pull_icon);
<a name="l00481"></a>00481                 refreshStateTextView = (TextView) refreshView
<a name="l00482"></a>00482                                 .findViewById(R.id.state_tv);
<a name="l00483"></a>00483                 refreshingView = refreshView.findViewById(R.id.refreshing_icon);
<a name="l00484"></a>00484                 refreshStateImageView = refreshView.findViewById(R.id.state_iv);
<a name="l00485"></a>00485                 <span class="comment">// 初始化上拉布局</span>
<a name="l00486"></a>00486                 pullUpView = loadmoreView.findViewById(R.id.pullup_icon);
<a name="l00487"></a>00487                 loadStateTextView = (TextView) loadmoreView
<a name="l00488"></a>00488                                 .findViewById(R.id.loadstate_tv);
<a name="l00489"></a>00489                 loadingView = loadmoreView.findViewById(R.id.loading_icon);
<a name="l00490"></a>00490                 loadStateImageView = loadmoreView.findViewById(R.id.loadstate_iv);
<a name="l00491"></a>00491         }
<a name="l00492"></a>00492 
<a name="l00493"></a>00493         @Override
<a name="l00494"></a>00494         <span class="keyword">protected</span> <span class="keywordtype">void</span> onLayout(<span class="keywordtype">boolean</span> changed, <span class="keywordtype">int</span> l, <span class="keywordtype">int</span> t, <span class="keywordtype">int</span> r, <span class="keywordtype">int</span> b)
<a name="l00495"></a>00495         {
<a name="l00496"></a>00496                 <span class="keywordflow">if</span> (!isLayout)
<a name="l00497"></a>00497                 {
<a name="l00498"></a>00498                         <span class="comment">// 这里是第一次进来的时候做一些初始化</span>
<a name="l00499"></a>00499                         refreshView = getChildAt(0);
<a name="l00500"></a>00500                         pullableView = getChildAt(1);
<a name="l00501"></a>00501                         loadmoreView = getChildAt(2);
<a name="l00502"></a>00502                         isLayout = <span class="keyword">true</span>;
<a name="l00503"></a>00503                         initView();
<a name="l00504"></a>00504                         refreshDist = ((ViewGroup) refreshView).getChildAt(0)
<a name="l00505"></a>00505                                         .getMeasuredHeight();
<a name="l00506"></a>00506                         loadmoreDist = ((ViewGroup) loadmoreView).getChildAt(0)
<a name="l00507"></a>00507                                         .getMeasuredHeight();
<a name="l00508"></a>00508                 }
<a name="l00509"></a>00509                 <span class="comment">// 改变子控件的布局，这里直接用(pullDownY + pullUpY)作为偏移量，这样就可以不对当前状态作区分</span>
<a name="l00510"></a>00510                 refreshView.layout(0,
<a name="l00511"></a>00511                                 (<span class="keywordtype">int</span>) (pullDownY + pullUpY) - refreshView.getMeasuredHeight(),
<a name="l00512"></a>00512                                 refreshView.getMeasuredWidth(), (int) (pullDownY + pullUpY));
<a name="l00513"></a>00513                 pullableView.layout(0, (<span class="keywordtype">int</span>) (pullDownY + pullUpY),
<a name="l00514"></a>00514                                 pullableView.getMeasuredWidth(), (int) (pullDownY + pullUpY)
<a name="l00515"></a>00515                                                 + pullableView.getMeasuredHeight());
<a name="l00516"></a>00516                 loadmoreView.layout(0,
<a name="l00517"></a>00517                                 (<span class="keywordtype">int</span>) (pullDownY + pullUpY) + pullableView.getMeasuredHeight(),
<a name="l00518"></a>00518                                 loadmoreView.getMeasuredWidth(),
<a name="l00519"></a>00519                                 (int) (pullDownY + pullUpY) + pullableView.getMeasuredHeight()
<a name="l00520"></a>00520                                                 + loadmoreView.getMeasuredHeight());
<a name="l00521"></a>00521         }
<a name="l00522"></a>00522 
<a name="l00523"></a>00523         <span class="keyword">class </span>MyTimer
<a name="l00524"></a>00524         {
<a name="l00525"></a>00525                 <span class="keyword">private</span> Handler handler;
<a name="l00526"></a>00526                 <span class="keyword">private</span> Timer timer;
<a name="l00527"></a>00527                 <span class="keyword">private</span> MyTask mTask;
<a name="l00528"></a>00528 
<a name="l00529"></a>00529                 <span class="keyword">public</span> MyTimer(Handler handler)
<a name="l00530"></a>00530                 {
<a name="l00531"></a>00531                         this.handler = handler;
<a name="l00532"></a>00532                         timer = <span class="keyword">new</span> Timer();
<a name="l00533"></a>00533                 }
<a name="l00534"></a>00534 
<a name="l00535"></a>00535                 <span class="keyword">public</span> <span class="keywordtype">void</span> schedule(<span class="keywordtype">long</span> period)
<a name="l00536"></a>00536                 {
<a name="l00537"></a>00537                         <span class="keywordflow">if</span> (mTask != null)
<a name="l00538"></a>00538                         {
<a name="l00539"></a>00539                                 mTask.cancel();
<a name="l00540"></a>00540                                 mTask = null;
<a name="l00541"></a>00541                         }
<a name="l00542"></a>00542                         mTask = <span class="keyword">new</span> MyTask(handler);
<a name="l00543"></a>00543                         timer.schedule(mTask, 0, period);
<a name="l00544"></a>00544                 }
<a name="l00545"></a>00545 
<a name="l00546"></a>00546                 <span class="keyword">public</span> <span class="keywordtype">void</span> cancel()
<a name="l00547"></a>00547                 {
<a name="l00548"></a>00548                         <span class="keywordflow">if</span> (mTask != null)
<a name="l00549"></a>00549                         {
<a name="l00550"></a>00550                                 mTask.cancel();
<a name="l00551"></a>00551                                 mTask = null;
<a name="l00552"></a>00552                         }
<a name="l00553"></a>00553                 }
<a name="l00554"></a>00554 
<a name="l00555"></a>00555                 <span class="keyword">class </span>MyTask <span class="keyword">extends</span> TimerTask
<a name="l00556"></a>00556                 {
<a name="l00557"></a>00557                         <span class="keyword">private</span> Handler handler;
<a name="l00558"></a>00558 
<a name="l00559"></a>00559                         <span class="keyword">public</span> MyTask(Handler handler)
<a name="l00560"></a>00560                         {
<a name="l00561"></a>00561                                 this.handler = handler;
<a name="l00562"></a>00562                         }
<a name="l00563"></a>00563 
<a name="l00564"></a>00564                         @Override
<a name="l00565"></a>00565                         <span class="keyword">public</span> <span class="keywordtype">void</span> run()
<a name="l00566"></a>00566                         {
<a name="l00567"></a>00567                                 handler.obtainMessage().sendToTarget();
<a name="l00568"></a>00568                         }
<a name="l00569"></a>00569 
<a name="l00570"></a>00570                 }
<a name="l00571"></a>00571         }
<a name="l00572"></a>00572 
<a name="l00579"></a><a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html">00579</a>         <span class="keyword">public</span> <span class="keyword">interface </span><a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html" title="刷新加载回调接口">OnRefreshListener</a>
<a name="l00580"></a>00580         {
<a name="l00584"></a>00584                 <span class="keywordtype">void</span> <a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html#a54dbbaff3fae4c145e5a3efb3bc0b173" title="刷新操作">onRefresh</a>(<a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html" title="自定义的布局，用来管理三个子控件，其中一个是下拉头，一个是包含内容的pullableView（可以是实现Pullable接口的的任何View）， 还有一个上拉头，更多详解见博客http://blog.csdn.net/zhongkejingwang/article/details/38868463">PullToRefreshLayout</a> pullToRefreshLayout);
<a name="l00585"></a>00585 
<a name="l00589"></a>00589                 <span class="keywordtype">void</span> <a class="code" href="interfacecom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout_1_1_on_refresh_listener.html#aec3a5a5dc7b68d7838a447199534ebf2" title="加载操作">onLoadMore</a>(<a class="code" href="classcom_1_1zxx_1_1_pull_refresh_1_1_pull_to_refresh_layout.html" title="自定义的布局，用来管理三个子控件，其中一个是下拉头，一个是包含内容的pullableView（可以是实现Pullable接口的的任何View）， 还有一个上拉头，更多详解见博客http://blog.csdn.net/zhongkejingwang/article/details/38868463">PullToRefreshLayout</a> pullToRefreshLayout);
<a name="l00590"></a>00590         }
<a name="l00591"></a>00591 
<a name="l00592"></a>00592 }
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated at 2015年二月4日 星期三 18:11:09 for zxxhouse by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
